package com.six.goods.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six.core.entity.Checkgoods;
import com.six.core.entity.Goods;
import com.six.core.util.JwtUtil;
import com.six.core.util.WebUtil;
import com.six.core.vo.Result;
import com.six.goods.mapper.CheckgoodsMapper;
import com.six.goods.mapper.GoodsMapper;
import com.six.goods.service.CheckgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author wang
* @description 针对表【acl_checkgoods】的数据库操作Service实现
* @createDate 2023-02-28 10:51:04
*/
@Service
public class CheckgoodsServiceImpl extends ServiceImpl<CheckgoodsMapper, Checkgoods> implements CheckgoodsService {

    @Autowired
    private CheckgoodsMapper checkgoodsMapper;
    @Autowired
    private GoodsMapper goodsMapper;

    //商品审核----审核状态下拉信息
    @Override
    public Result selecheckgoods() {
        List<Checkgoods> checkgoods = checkgoodsMapper.selectList(null);
        if (checkgoods != null){
            return new Result(2000,"审核状态下拉信息--查询成功",checkgoods);
        }
        return new Result(5000,"审核状态下拉信息--查询失败");
    }

    //商品审核----修改审核状态（状态码  备注  审核人）
    @Override
    public Result updateState(Goods goods) {

        //获取登录人的id
        HttpServletRequest request = WebUtil.getRequest();
        String token = request.getHeader("token");
        Map<String, Object> map = JwtUtil.decodeJWT(token);
        Integer empId = (Integer) map.get("empId");

        Goods goods1 = goodsMapper.selectById(goods.getId());
        QueryWrapper<Checkgoods> Wrapper = new QueryWrapper<>();
        Wrapper.eq("goodsid",goods1.getGoodsid());


        Checkgoods checkgoods1 = checkgoodsMapper.selectOne(Wrapper);
        checkgoods1.setGmtModified(new Date());
        checkgoods1.setEmpid(empId);
        checkgoods1.setRemark(goods.getCheckgoods().getRemark());
        checkgoods1.setState(goods.getCheckgoods().getState());
        int i = checkgoodsMapper.updateById(checkgoods1);

        goods.setState(1);
        int i1 = goodsMapper.updateById(goods);
        if (i>0){
            return new Result(2000,"修改成功");
        }else {
            return new Result(5000,"修改失败");
        }
    }


}




